package com.gis507.test.AISTest2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 1、继承Mapper类
 * 2、确定输入和输出类型
 * 3、重写map方法
 */
public class AisMapper extends Mapper<LongWritable, Text, LongWritable, AisBean> {

    private LongWritable outK = new LongWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1
        String line = value.toString();

        //2
        String[] comment = line.split(",");

        //3
        AisBean ais = new AisBean();

        ais.setMmsi(comment[0]);
        ais.setSpeed(comment[1]);
        ais.setUnixTime(Long.parseLong(comment[2]));
        ais.setLat_d(Double.parseDouble(comment[3]));
        ais.setLat_d(Double.parseDouble(comment[4]));

        //4
        outK.set(Long.parseLong(comment[2]));

        context.write(outK,ais);

    }
}
